/*
 * @Author: giteezr 2250368646@qq.com
 * @Date: 2024-01-10 15:20:01
 * @LastEditors: giteezr 2250368646@qq.com
 * @LastEditTime: 2024-03-30 11:04:03
 * @FilePath: \vue3+nodeJs\houtaiguanli\management-node\service\getRoadStakeNumInfosByRoadId.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const db = require('../db/blog')

class GetCarRoadService {
  // 车辆列表
  getCarRoad(req, res) {
    const cardevicegpsstatusresplistSql = 'SELECT * FROM cardevicegpsstatusresplist'
    const roadinfoentitylistSql = 'SELECT * FROM roadinfoentitylist'
    var obj = {
      cardevicegpsstatusresplist: [],
      roadinfoentitylist: []
    }
    db.query(cardevicegpsstatusresplistSql, (err, results) => {
      if (err) return res.back(err)
      obj.cardevicegpsstatusresplist = JSON.parse(JSON.stringify(results))
      db.query(roadinfoentitylistSql, (err, results) => {
        if (err) return res.back(err)
        obj.roadinfoentitylist = JSON.parse(JSON.stringify(results))
        return res.send({
          status: 0,
          message: 'success！',
          data: obj
        })
      })
    })
  }
  // 首页查询
  getInitChartData(req, res) {
    const rankingSql = 'SELECT * FROM ranking'
    const rubbishStatisticsSql = 'SELECT * FROM rubbishStatistics'
    const workAnalysisSql = 'SELECT * FROM workAnalysis'
    var obj = {
      ranking: [],
      rubbishStatistics: [],
      workAnalysis: []
    }
    db.query(rankingSql, (err, results) => {
      if (err) return res.back(err)
      obj.ranking = JSON.parse(JSON.stringify(results[0]))
      db.query(rubbishStatisticsSql, (err, results) => {
        if (err) return res.back(err)
        let objt={}
        objt.name = [];
        objt.value  = [];
        results.forEach((x) => {
          objt.name.push(x.name);
          objt.value.push(x.value);
        });
        obj.rubbishStatistics = JSON.parse(JSON.stringify(objt))
        db.query(workAnalysisSql, (err, results) => {
          if (err) return res.back(err)
          let objs={}
          objs.currentMonthCount = [];
          objs.lastMonthCount  = [];
          objs.orgName  = [];
          results.forEach((x) => {
            objs.currentMonthCount.push(x.currentMonthCount);
            objs.lastMonthCount.push(x.lastMonthCount);
            objs.orgName.push(x.orgName);
            
          });
          obj.workAnalysis = JSON.parse(JSON.stringify(objs))
          return res.send({
            status: 0,
            message: 'success！',
            data: obj
          })
        })
      })
    })
  }
  // 评分排名
  getRanking(req, res) {
    const rankingSql = 'SELECT * FROM ranking'
    db.query(rankingSql, (err, results) => {
      if (err) return res.back(err)
      return res.send({
        status: 0,
        message: 'success！',
        data: results[0]
      })
    })
  }
  // 洒落物排名
  getRubbishStatistics(req, res) {
    const rubbishStatisticsSql = 'SELECT * FROM rubbishStatistics'
    db.query(rubbishStatisticsSql, (err, results) => {
      if (err) return res.back(err)
      let obj = {}
      obj.name = [];
      obj.value = [];
      results.forEach((x) => {
        obj.name.push(x.name);
        obj.value.push(x.value);
      });
      return res.send({
        status: 0,
        message: 'success！',
        data: obj
      })
    })
  }
  // 台班分析(首页的)
  getWorkAnalysis(req, res) {
    const workAnalysisSql = 'SELECT * FROM workAnalysis'
    db.query(workAnalysisSql, (err, results) => {
      if (err) return res.back(err)
      let obj = {}
      obj.currentMonthCount = [];
      obj.lastMonthCount = [];
      obj.orgName = [];
      results.forEach((x) => {
        obj.currentMonthCount.push(x.currentMonthCount);
        obj.lastMonthCount.push(x.lastMonthCount);
        obj.orgName.push(x.orgName);
      });
      return res.send({
        status: 0,
        message: 'success！',
        data: obj
      })
    })
  }
  // 班次详情
  getWorkDetail(req, res) {
    const workDetailSql = 'SELECT * FROM workDetail'
    db.query(workDetailSql, (err, results) => {
      if (err) return res.back(err)
      let obj = {}
      obj.list = [];
      results.forEach((x) => {
        obj.list.push(x);
      });
      return res.send({
        status: 0,
        message: 'success！',
        data: obj
      })
    })
  }
  // 台班查询
  getWorkqueryscoreinfo(req, res) {
    const workqueryscoreinfoSql = 'SELECT * FROM workqueryscoreinfo'
    db.query(workqueryscoreinfoSql, (err, results) => {
      if (err) return res.back(err)
      return res.send({
        status: 0,
        message: 'success！',
        data: results
      })
    })
  }
  // 台班查询-打分依据
  getWorkqueryscorejudge(req, res) {
    const workqueryscorejudgeSql = 'SELECT * FROM workqueryscorejudge'
    db.query(workqueryscorejudgeSql, (err, results) => {
      if (err) return res.back(err)
      let obj = {}
      obj.list = [];
      results.forEach((x) => {
        obj.list.push(x);
      });
      return res.send({
        status: 0,
        message: 'success！',
        data: obj
      })
    })
  }
  // 指标分析-保洁时间间隔
  getTtargetStatisticsHeadScore(req, res) {
    const workqueryscoreinfoSql = 'SELECT * FROM targetStatisticsHeadScore'
    db.query(workqueryscoreinfoSql, (err, results) => {
      if (err) return res.back(err)
      return res.send({
        status: 0,
        message: 'success！',
        data: results
      })
    })
  }
  //指标分析-道路清洁效果
  getTargetstatisticsbackscore(req, res) {
    const workqueryscoreinfoSql = 'SELECT * FROM targetstatisticsbackscore'
    db.query(workqueryscoreinfoSql, (err, results) => {
      if (err) return res.back(err)
      return res.send({
        status: 0,
        message: 'success！',
        data: results
      })
    })
  }
  // 指标分析-洒落物统计
  getTargetstatisticsrubbishstatistics(req, res) {
    const workqueryscoreinfoSql = 'SELECT * FROM targetstatisticsrubbishstatistics'
    db.query(workqueryscoreinfoSql, (err, results) => {
      if (err) return res.back(err)
      return res.send({
        status: 0,
        message: 'success！',
        data: results
      })
    })
  }
  // 指标分析-保洁能力
  getTargetstatisticsconscore(req, res) {
    const workqueryscoreinfoSql = 'SELECT * FROM targetstatisticsconscore'
    db.query(workqueryscoreinfoSql, (err, results) => {
      if (err) return res.back(err)
      return res.send({
        status: 0,
        message: 'success！',
        data: results
      })
    })
  }
  // 指标分析-重点保洁路段
  getTargetstatisticsimportantroad(req, res) {
    const workqueryscoreinfoSql = 'SELECT * FROM targetstatisticsimportantroad'
    db.query(workqueryscoreinfoSql, (err, results) => {
      if (err) return res.back(err)
      return res.send({
        status: 0,
        message: 'success！',
        data: results
      })
    })
  }
  // 指标分析-衰减曲线分析
  getScoreattenuation(req, res) {
    const workqueryscoreinfoSql = 'SELECT * FROM scoreattenuation'
    db.query(workqueryscoreinfoSql, (err, results) => {
      if (err) return res.back(err)
      return res.send({
        status: 0,
        message: 'success！',
        data: results
      })
    })
  }
  // 指标分析-保洁趋势分析
  getScoreComparison(req, res) {
    const workqueryscoreinfoSql = 'SELECT * FROM scoreComparison'
    db.query(workqueryscoreinfoSql, (err, results) => {
      if (err) return res.back(err)
      return res.send({
        status: 0,
        message: 'success！',
        data: results
      })
    })
  }
  // 指标分析-经济效益
  getWongetrkqueryscorejudge(req, res) {
    const workqueryscoreinfoSql = 'SELECT * FROM workqueryscorejudge'
    db.query(workqueryscoreinfoSql, (err, results) => {
      if (err) return res.back(err)
      return res.send({
        status: 0,
        message: 'success！',
        data: results
      })
    })
  }
}

module.exports = new GetCarRoadService()
